function figDhaqtool_VidOpenFcn(fig, e )
%FIGDHAQTOOL_VIDOPENFCN Summary of this function goes here
%   Detailed explanation goes here

% Try to reuse old VideoInput
vid= [];
e=[];
while isempty(vid)
    e.Section='VideoInput';
    e.Keys= {'Adaptor', 'DeviceID', 'Format'};
    SelectedVid = figDhaqtool_IniRead( fig, e );
    vid=imaqdevice_OpenFcn(SelectedVid{1}, str2num(SelectedVid{2}), SelectedVid{3}); %#ok<ST2NM>
    if isempty(vid)
        figDhaqtool_IniDelete( fig, e );        
        try
            e=[];
            e.Adaptor= SelectedVid{1};
            e.DeviceID= str2num(SelectedVid{2}); %#ok<*ST2NM>
            e.Format= SelectedVid{3};
            figDhaqtool_VidOpenFailedFcn(fig, e);
        catch ex
            throw(ex)
        end
    end
end

figDhaqtool_SetAppData(fig, 'vid', vid);

end

